fix(docitem): render frontMatter.head tags so custom canonicals reach built HTML#879
Merged
Conversation
… built HTML Signed-off-by: amaan-bhati <amaanbhati49@gmail.com>
nehagup
approved these changes
Jun 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #877, which added
headfrontmatter to the Regression Testing and Black Box Testing glossary pages to override their canonical tags to point at the corresponding Keploy blog posts instead of the docs pages. After that PR was merged and deployed, both pages still showed the self-referential docs canonical inview-sourceon production - the blog canonical never appeared.Issue - reference share prod:
Why It Wasn't Working
PR #877 added the correct frontmatter to both markdown files:
The data was there, parsed correctly, and exported by the MDX compiler - but Docusaurus 3.x never renders
frontMatter.headfor doc pages. Two things were happening:DocFrontMatterSchemahas noheadfield. The schema inplugin-content-docs/lib/frontMatter.jsuses.unknown(), which silently accepts the key without error but nothing downstream ever reads it. The built-inDocItem/Metadatacomponent only passestitle,description,keywords, andimageto the head -frontMatter.headis ignored entirely.SiteMetadataalways wins.theme-classic/lib/theme/SiteMetadata/index.jscontains aCanonicalUrlHeaderscomponent that unconditionally injects a self-referential<link rel="canonical">on every page based on the current URL. Since nothing was overriding it, this was the only canonical in the built HTML.The Fix
Added rendering of
frontMatter.headinside the existing<Head>block insrc/theme/DocItem/index.js:This works because
DocItemrenders deeper in the React component tree thanSiteMetadata. React Helmet - which Docusaurus uses for SSG head management - keeps only the last<link rel="canonical">it encounters across all<Head>components. SinceDocItemrenders afterSiteMetadata, its canonical replaces the self-referential docs one in the final static HTML.Testing
Build output check:
Browser check (
npm run serve):view-source:http://localhost:3000/docs/concepts/reference/glossary/regression-testing/→ blog canonical ✅view-source:http://localhost:3000/docs/concepts/reference/glossary/black-box-testing/→ blog canonical ✅Regression check - pages without
headfrontmatter are unaffected:Sources & References
Upstream Docusaurus references:
facebook/docusaurus-SiteMetadatasource - confirmsCanonicalUrlHeadersalways runsfacebook/docusaurus-DocItem/Metadatasource - confirmsheadfrontmatter is never read for doc pagesfacebook/docusaurus-DocFrontMatterschema - noheadfield in the schemaRelated:
headfrontmatter to the markdown files (the change that was supposed to work but didn't)